import sys
import os
import shutil

def cpfiles_in_dir(destdir, srcdir):
	#cwd = os.getcwd()
	filelist = os.listdir(srcdir)
	for myfile in filelist:
		filepath = srcdir + '/' + myfile
		#print filepath
		#print destdir
		shutil.copy(filepath, destdir)

def mkdirs(dirpath):
	cwd = os.getcwd()
	#print cwd
	dir_list = dirpath.split('/')
	#print dir_list
	for single_dir in dir_list:
		#print single_dir
		if single_dir == '':
			break;
		if os.path.exists(single_dir):
			os.chdir(single_dir)
		else:
			os.mkdir(single_dir)
			os.chdir(single_dir)
	os.chdir(cwd);

#mkdirs('tmp/im/gf/df/se/s/dddd/fd/s')
#mkdirs('tmp/im/gf/ff/fdsg/sgc/vvv/')

patchdir_name = 'patch.me'

fs = open('patch.txt')
paths = fs.readlines()

#print paths

#cpfiles_in_dir('patch.me', 'src/ui')

for path in paths:
	if os.path.isdir(path):
		if os.path.exists(patchdir_name):
			os.chdir(patchdir_name)
		else:
			os.mkdir(patchdir_name)
			os.chdir(patchdir_name)
		mkdirs(path)
		os.chdir('..')
		#a = patchdir_name
		#b = patchdir_name + '/' +path 
		#print os.getcwd()
		#print b
		#shutil.copy(path,patchdir_name + '/' +path)
		cpfiles_in_dir(patchdir_name + '/' +path, path)
	else:
		if os.path.exists(patchdir_name):
			os.chdir(patchdir_name)
		else:
			os.mkdir(patchdir_name)
			os.chdir(patchdir_name)
		filename = path.split('/')[-1]
		dirpath_exp_filename = path.split(filename)[0]
		#print filename
		#print dir_exp_filename
		#print path
		mkdirs(dirpath_exp_filename)
		os.chdir('..')
		cwd = os.getcwd()
		print cwd
		print path
		print patchdir_name + '/' + dirpath_exp_filename
		shutil.copy(path, patchdir_name + '/' + dirpath_exp_filename)
	#print isdir






while 1:
	pass
fs = open('patch.txt')
str = fs.readlines()

print str[0]

#os.mkdir('tmp')
#os.chdir('tmp')
#os.mkdir('main')
pos = str[0].find('/')
read_str = str[0].split('/')
count = len(read_str)
num = 0
os.mkdir('tmp')
os.chdir('tmp')

for mydir in read_str:
	if num < count - 1: 
		os.mkdir(mydir)
		os.chdir(mydir)
		num += 1
	
#print read_str[0],read_str[1],read_str[2]


#print read_str


#srcpath = sys.argv[1]
#inspath = sys.argv[2]

def readfile(path):
	fd = open(path, 'r')
	res = fd.read()
	fd.close()
	return res

def writefile(path, text):
	fd = open(path, 'w')
	fd.write(text)
	fd.close()

#src = readfile(srcpath)
#ins = readfile(inspath)
#if src.find(ins) < 0:
#	writefile(srcpath, src + ins)

